package com.atguigui.leetcode1;

import java.util.Arrays;

/**
 * 2341.数组能形成多少数对
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/2/16 8:42
 */
public class P2341MaximumNumberOfPairsInArray {
    public static void main(String[] args) {
        Solution solution = new P2341MaximumNumberOfPairsInArray().new Solution();
        // TO TEST
    }

    class Solution {
        public int[] numberOfPairs(int[] nums) {
            int[] ans = new int[2];
            int n = 0;
            int s = nums.length;

            boolean[] num = new boolean[101];
            Arrays.fill(num, false);

            for (int i = 0; i < nums.length; i++) {
                if (num[nums[i]] == true) {
                    n++;
                    s -= 2;
                    num[nums[i]] = false;
                } else if (num[nums[i]] == false) {
                    num[nums[i]] = true;
                }
            }

            ans[0] = n;
            ans[1] = s;
            return ans;
        }
    }
}
